int searchInsert(int* nums, int numsSize, int target){
    int left = 0, right = numsSize - 1;
    if(target <= nums[0]) {
        return 0;
    }
    if(target == nums[numsSize - 1]) {
        return numsSize - 1;
    }
    if(target > nums[numsSize - 1]) {
        return numsSize;
    }
    while(left < right) {
        int mid = (left + right) / 2;
        if(left == right - 1) {
            if(target <= nums[left]) {
                return left;
            }
            else {
                return right;
            }
        }
        if(nums[mid] == target) {
            return mid;
        }
        else if(nums[mid] > target) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    return 0;
}